﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.Entities
{
    [Serializable]
    public class CriteriaTypeOne : BaseCriteria
    {
        public int MaxValue { get; set; }
        public int MinValue { get; set; }
        public List<CriteriaChartData> CriteriaData { get; set; }
        public bool IsScreenable { get; set; }
        public Guid CriteriaLevel3Id { get; set; }
        public Guid? FilterCriteriaGroupId { get; set; }
        public bool IsDataPoint { get; set; }
        public string SelectedValue { get; set; }
        public string SelectedValueInformation { get; set; }

        public static CriteriaTypeOne CriteriaTypeOneWithGraph(CriteriaTypeOne criteriaTypeOne, List<CriteriaChartData> criteriaData)
        {
            return new CriteriaTypeOne()
            {
                Id = criteriaTypeOne.Id,
                Name = criteriaTypeOne.Name,
                CriteriaType = CriteriaTypeEnum.CriteriaType1,
                CriteriaData = criteriaData,
                MaxValue = (criteriaData != null && criteriaData.Count > 0) ? criteriaData.Max(d => d.XAxisValue) : 0,
                MinValue = (criteriaData != null && criteriaData.Count > 0) ? criteriaData.Min(d => d.XAxisValue) : 0,
                IsScreenable = criteriaTypeOne.IsScreenable
            };
        }
    }
}
